import Vue from 'vue'
import Router from 'vue-router'
import setting from '../settings'
import Layout from '@/layout'

Vue.use(Router)

// export default new Router({
//   routes: [
//     {
//       path: '/index',
//       name: 'Login',
//       component: Login
//     }
//   ]
// })

export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta:{
      title:setting.title
    }
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta:{
      title:setting.title
    }
  },
  {
    path: '/oidc-callback',
    component: () => import('@/views/odic/odicCallback'),
    hidden: true
  },
  {
    path: '/oidc-callback-error',
    component: () => import('@/views/odic/odicCallbackError'),
    hidden: true
  },
  {
    path: '/welcome',
    component: Layout,
    children: [{
      path: 'welcome',
      component: () => import('@/views/welcome/welcome'),
      name: 'Welcome',
    }]
  },
  {
    path: '/oidc-silent-renew',
    component: () => import('@/views/odic/oidcSilentRenew'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
]

export const asyncRoutes = [
  {
    path: '/home',
    component: Layout,
    redirect: '/home/dashboard',
    meta: { title: '首页', icon: 'component' },
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/order-dashboard'),
      name: 'Dashboard',
      meta: { title: '数据统计', icon: 'component' },
      hidden: true
    }]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order/list',
    name: 'order',
    meta: { title: '订单管理', icon: 'nested' },
    children: [
      {
        path: 'list',
        name: 'OrderList',
        component: () => import('@/views/order/order-list/order-list.vue'),
        meta: { title: '订单列表', icon: 'cluster', noCache: true, activeMenu: '/order' },
        hidden: false
      },
      {
        path: 'add',
        name: 'AddOrder',
        component: () => import('@/views/order/order-edit/order-edit'),
        meta: { title: '新增订单', icon: 'example', noCache: true, activeMenu: '/order' },
        hidden: false
      },
      {
        path: 'detail/:id(\\d+)',
        name: 'OrderDetail',
        component: () => import('@/views/order/order-detail/order-detail'),
        meta: { title: '订单详情', icon: 'example', noCache: true, activeMenu: '/order' },
        hidden: false
      },
      {
        path: 'edit/:id(\\d+)',
        name: 'EditSite',
        component: () => import('@/views/order/order-edit/order-edit'),
        meta: { title: '订单编辑', icon: 'example', noCache: true, activeMenu: '/order' },
        hidden: false
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
